/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:23:02 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class HoidapDAL : SqlProvider<HoidapEntity>
    {
        static HoidapDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                HoidapEntity entity = new HoidapEntity();
				entity.PK_iHoidapID = Int64.Parse("0"+dr["PK_iHoidapID"].ToString());
				entity.FK_iBaihocID = Int64.Parse("0"+dr["FK_iBaihocID"].ToString());
				entity.FK_iGiangvienID = Int64.Parse("0"+dr["FK_iGiangvienID"].ToString());
				entity.FK_iHocvienID = Int64.Parse("0"+dr["FK_iHocvienID"].ToString());
				entity.sNoidung = dr["sNoidung"].ToString();
				entity.dNgayhoidap =String.IsNullOrEmpty(dr["dNgayhoidap"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgayhoidap"].ToString());
                return entity;
            };
        }
        public static HoidapEntity GetOne(Int64 PK_iHoidapID)
        {
            string cmdName = "spHoidap_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iHoidapID", PK_iHoidapID);
            HoidapEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<HoidapEntity> GetAll()
        {
            string cmdName = "spHoidap_Get";
            return GetList(cmdName);
        }
        public static List<HoidapEntity> GetByFK_iBaihocID(Int64 FK_iBaihocID)
		{
			string cmdName = "spHoidap_GetByFK_FK_iBaihocID";
			SqlParameter p = new SqlParameter("@FK_iBaihocID",FK_iBaihocID);
			List<HoidapEntity> list = GetList(cmdName, p);
			return list;
		}public static List<HoidapEntity> GetByFK_iGiangvienID(Int64 FK_iGiangvienID)
		{
			string cmdName = "spHoidap_GetByFK_FK_iGiangvienID";
			SqlParameter p = new SqlParameter("@FK_iGiangvienID",FK_iGiangvienID);
			List<HoidapEntity> list = GetList(cmdName, p);
			return list;
		}public static List<HoidapEntity> GetByFK_iHocvienID(Int64 FK_iHocvienID)
		{
			string cmdName = "spHoidap_GetByFK_FK_iHocvienID";
			SqlParameter p = new SqlParameter("@FK_iHocvienID",FK_iHocvienID);
			List<HoidapEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(HoidapEntity entity)
        {
            string cmdName = "spHoidap_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(HoidapEntity entity)
        {
            string cmdName = "spHoidap_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iHoidapID)
        {
            string cmdName = "spHoidap_Delete";
            SqlParameter p = new SqlParameter("@PK_iHoidapID", PK_iHoidapID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(HoidapEntity entity)
        {
            SqlParameter[] p = new SqlParameter[6];
			p[0] = new SqlParameter("@PK_iHoidapID", entity.PK_iHoidapID);
			p[1] = new SqlParameter("@FK_iBaihocID", entity.FK_iBaihocID);
			p[2] = new SqlParameter("@FK_iGiangvienID", entity.FK_iGiangvienID);
			p[3] = new SqlParameter("@FK_iHocvienID", entity.FK_iHocvienID);
			p[4] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[5] = new SqlParameter("@dNgayhoidap", entity.dNgayhoidap);
            return p;
        }
        #endregion
       
    }
}